package com.fzg.controller;


import com.fzg.common.enums.ResponseWrapper;
import com.fzg.common.model.param.user.LoginParam;
import com.fzg.common.model.param.user.QueryUserConcernListParam;
import com.fzg.common.model.param.user.Register;
import com.fzg.common.model.param.user.UpdateUserNickNameParam;
import com.fzg.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author fzg
 * @since 2022-06-17
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * 用户登陆
     * @param param 参数
     * @return ResponseWrapper
     */

    @PostMapping("/login")
    public ResponseWrapper login(@RequestBody LoginParam param){
        return userService.login(param);
    }

    /**
     * 用户注册
     * @param param 参数
     * @return ResponseWrapper
     */
    @PostMapping("/register")
    public ResponseWrapper register(@RequestBody Register param){
        return userService.register(param);
    }

    /**
     * 验证用户名是否唯一
     * @return ResponseWrapper
     */
    @GetMapping("/checkUserName")
    public ResponseWrapper checkUserName(String userName){
        return userService.checkUserName(userName);
    }

    /**
     * 验证手机号是否被注册
     * @return ResponseWrapper
     */
    @GetMapping("/checkPhone")
    public ResponseWrapper checkPhone(String userPhone){
        return userService.checkPhone(userPhone);
    }

    /**
     * 检验token是否过期
     * @return ResponseWrapper
     */
    @GetMapping("/checkToken")
    public ResponseWrapper checkToken(){
        return ResponseWrapper.markSuccess(false);
    }

    /**
     * 获取这个用户所有信息
     * @return ResponseWrapper
     */
    @GetMapping("/getUserInfoByAid")
    public ResponseWrapper getUserInfoByAid(HttpServletRequest request, @RequestParam Integer userAid){
        return userService.getUserInfoByAid(request,userAid);
    }

    /**
     * 修改用户的昵称
     * @return ResponseWrapper
     */
    @PostMapping("/updateUserNickName")
    public ResponseWrapper updateUserNickName(@RequestBody UpdateUserNickNameParam param){
        return userService.updateUserNickName(param);
    }

    /**
     * 查询用户的关注用户列表和被关注用户列表
     * @return ResponseWrapper
     */
    @GetMapping("/queryUserConcernList")
    public ResponseWrapper queryUserConcernList(HttpServletRequest request, QueryUserConcernListParam param){
        return userService.queryUserConcernList(request,param);
    }

    /**
     * 测试视图
     */
    @GetMapping("/getData")
    public ResponseWrapper getView(){
        return userService.getData();
    }

}
